<%
layout("/layouts/platform.html"){
%>
<header class="header navbar bg-white shadow">
	    <div class="pull-right offscreen-right">
	         <a class="btn btn-default navbar-btn" href="${base}/platform/allot/add" data-toggle="modal" data-target="#addModal" ><i class="fa fa-plus"></i>&nbsp;新增</a>
		</div>
	</header>
<div class="panel-body" style="padding-top: 70px;">
		<div class="box">
			<div class="box-body">
				<div class="col-sm-12">
					<div class="row">
				        <table class="table table-bordered table-hover mg-t datatable">
            <thead>
            <tr>
				<th>主体名称</th>
				<th>学校名称</th>
				<th>产品类型</th>
				<th>主体分配比例</th>
				<th>学校分配比例</th>
				<th>培训师分配比例</th>
				<th>操作</th>
    		        </table>
	    			</div>
				</div>
			</div>
		</div>
	</div>
<div id="dialogDelete" class="modal fade bs-modal-sm" tabindex="-2" role="dialog" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h4 class="modal-title">删除</h4>
            </div>
            <div class="modal-body">
                <div class="row">
                    <div class="col-xs-12">
                        确定删除该数据吗？ <br/>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button id="ok" type="button" class="btn btn-primary" data-loading-text="正在删除...">确定</button>
            </div>
        </div>
    </div>
</div>
<!-- 修改-->
	<div id="editModal" class="modal fade bs-modal-sm"   tabindex="-3" role="dialog" aria-hidden="true">
	    <div id="editModalDialog" class="modal-dialog " >
	        <div class="modal-content">
	        
	        </div>
	    </div>
	</div>
	<!-- 新增-->
	<div id="addModal" class="modal fade bs-modal-sm"   tabindex="-3" role="dialog" aria-hidden="true">
	    <div id="addModalDialog" class="modal-dialog " >
	        <div class="modal-content">
	        
	        </div>
	    </div>
	</div>
<script language="JavaScript">
    var datatable;
    function initDatatable() {
        datatable = $('.datatable').DataTable({
            "dom": '<"toolbar">frtip',
            "searching": false,
            "processing": false,
            "serverSide": true,
            "select": true,
            "ordering": true,
            "language": {
                "url": "${base}/assets/plugins/datatables/cn.json"
            },
            "preDrawCallback": function () {
                sublime.showLoadingbar($(".main-content"));
            },
            "drawCallback": function () {
                sublime.closeLoadingbar($(".main-content"));
            },
            "ajax": {
                "url": "${base}/platform/allot/data",
                "type": "post",
                "data": function (d) {
                	d.name=$('#nameStr').val();
                }
            },
            "order": [[0, "desc"]],
            "columns": [
				{"data": "company_name", "bSortable": true},
				{"data": "school_name", "bSortable": true},
				{"data": "product_name", "bSortable": true},
				{"data": "company_ratio", "bSortable": true},
				{"data": "school_ratio", "bSortable": true},
				{"data": "trainer_ratio", "bSortable": true}
            ],
            "columnDefs": [
                {
                    "render": function (data, type, row) {
                        return '<div>'
						 + '<a class="btn btn-xs btn btn-default " href="${base}/platform/allot/edit/' + row.id + '" data-toggle="modal" data-target="#editModal"><i class="fa fa-edit"></i>&nbsp;修改</a> '
						 + '<a class="btn btn-xs btn btn-default " href="javascript:;" onclick="del(\''+ row.id+ '\')"><i class="glyphicon glyphicon-trash"></i>删除</a>'
						 + '</div>';
                    },
                    "targets": 6
                }
            ]
        });
    }
    function del(id) {
        var dialog = $("#dialogDelete");
        dialog.modal("show");
        dialog.find("#ok").unbind("click");
        dialog.find("#ok").bind("click", function (event) {
            $.post("${base}/platform/allot/delete/" + id, {}, function (data) {
                if (data.code == 0) {
                    datatable.ajax.reload(null,false);
                } else {
                    Toast.error(data.msg);
                }
                dialog.modal("hide");
            }, "json");
        });
    }
    $(function () {
        initDatatable();
        $("#addModal").on("hidden.bs.modal", function () {
            $(this).removeData("bs.modal");
        });
		$("#editModal").on("hidden.bs.modal", function () {
            $(this).removeData("bs.modal");
        });
    });
    
    
</script>
<%}%>
